package work;

import java.util.Random;
import java.util.Scanner;

public class LoginAndRegister {
    public static void menu() {
        System.out.println("******欢迎进入奖客富翁系统******");
        System.out.println("          1. 注册               ");
        System.out.println("          2. 登录               ");
        System.out.println("          3. 抽奖               ");
        System.out.println("*****************************");
        System.out.println("请选择菜单:");
    }

    public static void main(String[] args) {
        String choice = "y";
        String s1 = "0";
        String s2;
        int password = 0;
        int password2;
        boolean justice = false;
        boolean justice2 = false;
        while (choice.equals("y")) {
            menu();
            Scanner sc = new Scanner(System.in);
            int input = sc.nextInt();
            switch (input) {
                case 1: {
                    System.out.println("[奖客富翁系统>注册]");
                    System.out.println("请填写个人注册信息");
                    System.out.println("用户名:");
                    s1 = sc.next();
                    System.out.println("密码");
                    password = sc.nextInt();
                    System.out.println("注册成功,请记好您的会员卡号");
                    System.out.println("用户名   密码   会员卡号");
                    System.out.println(s1 + password + random());
                    System.out.println("继续吗(y/n):");
                    choice = sc.next();
                }break;//这里登录以后将用户名和密码已经存了起来
                case 2: {
                    System.out.println("[奖客富翁系统>登录]");
                    System.out.println("请输入您的卡号:");
                    s2 = sc.next();
                    System.out.println("请输入密码:");
                    password2 = sc.nextInt();
                    if ((s2.equals(s1)) && (password2 == password)) {
                        System.out.println("欢迎您 " + s2);
                        justice = true;
                        System.out.println("继续吗(y/n):");
                        choice = sc.next();
                    } else {
                        System.out.println("您输入的用户名或密码错误(可以重新进行登录)");
                        System.out.println("继续吗(y/n)");
                        choice = sc.next();
                    }
                }
                break;
                case 3: {
                        if(!justice) {
                            System.out.println("您还未登录,请先登录,继续吗(y/n)");
                            choice = sc.next();
                            break;
                        }
                        System.out.println("奖客富翁系统>抽奖");
                        System.out.println("请输入您的卡号:");
                        int num = sc.nextInt();
                        int[] arr = new int[5];
                        for (int i = 0; i < 5; i++) {
                            arr[i] = random();
                        }
                        System.out.println("本日的幸运数字为 " + arr[0] + " " + arr[1] + " " + arr[3] + " " + arr[4] + " " + arr[2]);
                        for (int i = 0; i < 5; i++) {
                            if (arr[i] == num) {
                                justice2 = true;
                                System.out.println("恭喜您,成为本日幸运会员!");
                                System.out.println("继续吗(y/n)");
                                choice = sc.next();
                                break;
                            }
                        }
                        if(!justice2)
                        System.out.println("抱歉,您不是本日的幸运会员");
                        System.out.println("继续吗(y/n)");
                        choice = sc.next();
                        break;
                    }
                    default:
                        System.out.println("您的输入有误,请重新输入:");
                }
            }
         System.out.println("系统退出,谢谢使用!");
        }

    public static int random() {
        Random random = new Random();
        int num = random.nextInt(9000) + 1000;
        //生成1000-9999的数
        return num;
    }
}

